package vn.axonactive.devday.jsf.session4;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import vn.axonactive.devday.jsf.model.security.AuthenticationProvider;


/**
 * The JSF {@link ManagedBean} to interact with login form.
 *
 */
@ManagedBean
@SessionScoped
public class LoginBean {
	
	@ManagedProperty(value="#{authenticationProvider}")
	private AuthenticationProvider authenticationProvider;
	
	/**
	 * login id;
	 */
	
	private String username;
	/**
	 * password;
	 */
	private String password;
	
	
	/**
	 * Do authentication then decides where to go next.
	 * 
	 * @return a String which decides which view should be navigated to.
	 */
	public String authenticate()
	{
		boolean isValid = authenticationProvider.authenticate(username, password);
		if(isValid)
		{
			return "success";
		}
		return "fail";
	}

	public String getUsername() {
		return username;
	}


	public void setUsername(String username) {
		this.username = username;
	}


	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}


	public void setAuthenticationProvider(
			AuthenticationProvider authenticationProvider) {
		this.authenticationProvider = authenticationProvider;
	}


	

}
